/*
Anup Gampa
Proposal title: (Ideo)Logical Reasoning: Ideology Impairs Sound Reasoning


HYPOTHESES

Stated-Hyp1: "What is the impact of participant ideology on soundness ratings of
arguments." (p. 2)

	Test-Hyp1: Rate of correct answers will vary between matched vs. unmatched ideology statements.

Stated-Hyp2: "Is ideological bias more pronouneced in one [political] group versus the other" (p. 2)

	Test-Hyp2: Political ideology will moderate the effect of ideological mismatch of statements on probability of correct answers

********************************************************************************
NOTES
- analysis plan included fixed effects (p. 2).
*/

clear all
use "gampa616.dta", clear


* VARIABLES

* TREATMENT
	tab xtess181
	
* each treatment group was asked 4 questions; identify question number by group 
	rename	q5a	groupA1
	rename	q6a	groupA2
	rename	q7a	groupA3
	rename	q8a	groupA4
	rename	q9a	groupB1
	rename	q10a	groupB2
	rename	q11a	groupB3
	rename	q12a	groupB4
	rename	q13a	groupC1
	rename	q14a	groupC2
	rename	q15a	groupC3
	rename	q16a	groupC4
	rename	q17a	groupD1
	rename	q18a	groupD2
	rename	q19a	groupD3
	rename	q20a	groupD4
	rename	q21a	groupE1
	rename	q22a	groupE2
	rename	q23a	groupE3
	rename	q24a	groupE4
	rename	q25a	groupF1
	rename	q26a	groupF2
	rename	q27a	groupF3
	rename	q28a	groupF4
	rename	q29a	groupG1
	rename	q30a	groupG2
	rename	q31a	groupG3
	rename	q32a	groupG4
	rename	q33a	groupH1
	rename	q34a	groupH2
	rename	q35a	groupH3
	rename	q36a	groupH4

* reshaping so that each row is a single question 
	reshape long groupA groupB groupC groupD groupE groupF groupG groupH, i(caseid) j(question)

	
	* from proposal, we know what issues each statement corresponds to
	lab def issue 1 "abortion" 2 "capital punishment" 3 "affirmative action" 4 "govt. intervention"
	gen issue=.
	replace issue=1 if xtess181==1& question==1
	replace issue=1 if xtess181==2& question==3
	replace issue=1 if xtess181==3& question==2
	replace issue=1 if xtess181==4& question==4
	replace issue=1 if xtess181==5& question==1
	replace issue=1 if xtess181==6& question==3
	replace issue=1 if xtess181==7& question==2
	replace issue=1 if xtess181==8& question==4
	
	replace issue=2 if xtess181==1& question==3
	replace issue=2 if xtess181==2& question==1
	replace issue=2 if xtess181==3& question==4
	replace issue=2 if xtess181==4& question==2
	replace issue=2 if xtess181==5& question==3
	replace issue=2 if xtess181==6& question==1
	replace issue=2 if xtess181==7& question==4
	replace issue=2 if xtess181==8& question==2
	
	replace issue=3 if xtess181==1& question==2
	replace issue=3 if xtess181==2& question==4
	replace issue=3 if xtess181==3& question==1
	replace issue=3 if xtess181==4& question==3
	replace issue=3 if xtess181==5& question==2
	replace issue=3 if xtess181==6& question==4
	replace issue=3 if xtess181==7& question==1
	replace issue=3 if xtess181==8& question==3	
	
	replace issue=4 if xtess181==1& question==4
	replace issue=4 if xtess181==2& question==2
	replace issue=4 if xtess181==3& question==3
	replace issue=4 if xtess181==4& question==1
	replace issue=4 if xtess181==5& question==4
	replace issue=4 if xtess181==6& question==2
	replace issue=4 if xtess181==7& question==3
	replace issue=4 if xtess181==8& question==1
	
	lab val issue issue
	tab issue
	
* is question conclusion liberal or conservative (from proposal)
	gen conclusion_lib=.
	replace conclusion_lib=1 if question==1 | question==2
	replace conclusion_lib=0 if question==3 | question==4
	tab conclusion_lib
	
* is statement sound or unsound? (from proposal)
	gen sound=1 if question==1 | question==3
	replace sound=0 if question==2|question==4
	tab sound
	
* is R liberal or conservative?
	codebook ideo_new
	recode ideo_new (1/3=1) (5/7=0) (*=.), gen(r_lib)
	tab r_lib, mis
	
* does question match R's ideology?
	gen match_ideology=.
		// match
	replace match_ideology= 1 if r_lib==1 & conclusion_lib==1
	replace match_ideology= 1 if r_lib==0 & conclusion_lib==0
		// mismatch
	replace match_ideology= 0 if r_lib==0 & conclusion_lib==1
	replace match_ideology= 0 if r_lib==1 & conclusion_lib==0

	tab match_ideology, mis
	

* OUTCOME
	// create a variable with response
	gen response=groupA
	replace response=groupB if response==.
	replace response=groupC if response==.
	replace response=groupD if response==.
	replace response=groupE if response==.
	replace response= groupF if response==.
	replace response=groupG if response==.
	replace response= groupH if response==.
	
	tab response, mis
	replace response=.r if response==-1
	
	lab def response 1 "sound, v. confident" 6 "unsound, v. confident" .r "refused"
	lab val response response 
	
	tab response, mis
	
	// did R answer evaluate logic correctly?
	gen correct=.
	replace correct=1 if sound==1 & response>=1 & response<=3
	replace correct=1 if sound==0 & response>=4 & response<=6
	replace correct=0 if sound==0 & response>=1 & response<=3
	replace correct=0 if sound==1 & response>=4 & response<=6
	
	tab correct, mis // 48 refused answers are missing

********************************************************************************	
* ANALYSIS
	
	* note: we will use fixed effects for caseid
	
	xtset caseid question
	// note: the "time" variable is the question number.
	
	
* Test-Hyp1: Rate of correct statements will vary between matched vs. unmatched ideology statements.
	xtreg correct i.match_ideology, fe
	// reject. 0.681
	tess 1.match_ideology, init(Gampa616)
	
*Test-Hyp2: Political ideology will moderate the effect of ideological mismatch of statements on probability of correct answers

	xtreg correct i.match_ideology##i.r_lib, fe
	// reject. 0.256
	tess 1.match_ideology#1.r_lib
